<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

/**
 * Class OrderExpress.
 *
 * @package namespace App\Repository\Models;
 */
class OrderExpress extends Model implements Transformable
{
    use TransformableTrait;
    use SoftDeletes;

    protected $table = 'order_express';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['type', 'order_code', 'waybill_number', 'express_company', 'express_money',
        'seller_id', 'remark', 'company_code', 'result', 'state'];

    protected $appends = ['type_name'];

    /**
     * 快递类型
     */
    const TYPE_LOGISTICS = 1;  //物流
    const TYPE_EXPRESS = 2;    //快递
    const TYPE_SEND_SELF = 3;  //自送
    const TYPE_TAKE_THEIR = 4;    //自提

    public static $type_map = [
        1 => '物流',
        2 => '快递',
        3 => '自送',
        4 => '自提',
    ];

    public function getTypeNameAttribute()
    {
        if(isset($this->attributes['type'])){
            return array_get(self::$type_map, $this->attributes['type'], '-');
        }
        return '-';
    }
}
